import request from '@/utils/request'

// 获取所有交易
export function getAllTrades() {
  return request({
    url: '/api/trades',
    method: 'get'
  })
}

// 根据ID获取交易
export function getTradeById(id) {
  return request({
    url: `/api/trades/${id}`,
    method: 'get'
  })
}

// 根据组合ID获取交易
export function getTradesByPortfolioId(portfolioId) {
  return request({
    url: `/api/trades/portfolio/${portfolioId}`,
    method: 'get'
  })
}

// 根据基金ID获取交易
export function getTradesByFundId(fundId) {
  return request({
    url: `/api/trades/fund/${fundId}`,
    method: 'get'
  })
}

// 根据组合ID和基金ID获取交易
export function getTradesByPortfolioAndFund(portfolioId, fundId) {
  return request({
    url: `/api/trades/portfolio/${portfolioId}/fund/${fundId}`,
    method: 'get'
  })
}

// 根据交易类型获取交易
export function getTradesByAction(action) {
  return request({
    url: `/api/trades/action/${action}`,
    method: 'get'
  })
}

// 根据交易状态获取交易
export function getTradesByStatus(status) {
  return request({
    url: `/api/trades/status/${status}`,
    method: 'get'
  })
}

// 根据日期范围获取交易
export function getTradesByDateRange(startDate, endDate) {
  return request({
    url: '/api/trades/date-range',
    method: 'get',
    params: { 
      startDate: startDate.format('YYYY-MM-DD'),
      endDate: endDate.format('YYYY-MM-DD')
    }
  })
}

// 根据组合ID和日期范围获取交易
export function getTradesByPortfolioAndDateRange(portfolioId, startDate, endDate) {
  return request({
    url: `/api/trades/portfolio/${portfolioId}/date-range`,
    method: 'get',
    params: { 
      startDate: startDate.format('YYYY-MM-DD'),
      endDate: endDate.format('YYYY-MM-DD')
    }
  })
}

// 创建交易
export function createTrade(data) {
  return request({
    url: '/api/trades',
    method: 'post',
    data
  })
}

// 更新交易
export function updateTrade(id, data) {
  return request({
    url: `/api/trades/${id}`,
    method: 'put',
    data
  })
}

// 更新交易状态
export function updateTradeStatus(id, status) {
  return request({
    url: `/api/trades/${id}/status`,
    method: 'patch',
    data: { status }
  })
}

// 删除交易
export function deleteTrade(id) {
  return request({
    url: `/api/trades/${id}`,
    method: 'delete'
  })
} 